/*
$LastChangedBy: bjsy01@gmail.com $
$LastChangedDate: 2014-06-06 05:14:55 +0000 (Fri, 06 Jun 2014) $
$Revision: 82 $

Description:

*/

import org.apache.commons.lang3.StringUtils;

public class Course implements Comparable {
	// Instance Variables
	private String courseName;
	private String courseID;
	private int    maxEnrolled;
	private int    currentEnrolled;
	private String startDate;
	private String endDate;
	private String courseSummary;

	// Constructors
	public Course(String courseName, String courseID, int maxEnrolled, int currentEnrolled, String startDate, String endDate, String courseSummary) {
		this.courseName      = courseName;
		this.courseID        = courseID;
		this.maxEnrolled     = maxEnrolled;
		this.currentEnrolled = currentEnrolled;
		this.startDate       = startDate;
		this.endDate         = endDate;
		this.courseSummary   = courseSummary;
	}

	// Methods
	/**
	* registerStudent()
	*/
	public Boolean registerStudent() {
		Boolean result = false; // assume failure
		if (currentEnrolled < maxEnrolled) {
			currentEnrolled++;
			result = true;
		}
		else {
			System.out.println("Course is full, cannot add a student.");
		}
		return result;
	}

	/**
	* unregisterStudent()
	*/
	public Boolean unregisterStudent() {
		Boolean result = false; // assume failure
		if (currentEnrolled > 0) {
			currentEnrolled--;
			result = true;
		}
		else {
			System.out.println("This course has no students, cannot delete a student.");
		}
		return result;
	}

	/**
	* isCourseFull()
	*/
	public Boolean isCourseFull() {
		return (currentEnrolled == maxEnrolled);
	}

	/**
	* getCurrentEnrolled()
	*/
	public int getCurrentEnrolled() {
		return currentEnrolled;
	}

	/**
	* getMaxEnrolled()
	*/
	public int getMaxEnrolled() {
		return maxEnrolled;
	}

	/**
	* getID()
	*/
	public String getID() {
		return courseID;
	}

	/**
	* getName()
	*/
	public String getName() {
		return courseName;
	}

	/**
	* getSummary()
	*/
	public String getSummary() {
		return courseSummary;
	}

	/**
	* getStartDate()
	*/
	public String getStartDate() {
		return startDate;
	}

	/**
	* getEndDate()
	*/
	public String getEndDate() {
		return endDate;
	}

	/**
	* getCourseInfo()
	* @return toString()
	*/
	public String getCourseInfo() {
		int courseIDColLen = 7;
		int courseNameColLen = 14;
		int maxEnrolledColLen = 0;
		int currentEnrolledColLen = 10;
		int startDateColLen = 0;
		int endDateColLen = 9;
		int courseSummaryColLen = 0;
		int i = maxEnrolled;
		int n = currentEnrolled;
		String strMaxEnrolled = "" + i;
		String strCurrentEnrolled = "" + n;
		String courseInfo = StringUtils.rightPad(courseID,courseIDColLen,"") +
							StringUtils.rightPad(courseName,courseNameColLen,"") +
							StringUtils.rightPad(strMaxEnrolled + " / ",maxEnrolledColLen,"") +
							StringUtils.rightPad(strCurrentEnrolled,currentEnrolledColLen,"") +
							StringUtils.rightPad(startDate + "-",startDateColLen,"") +
							StringUtils.rightPad(endDate,endDateColLen,"") +
							StringUtils.rightPad(courseSummary,courseSummaryColLen,"");
		
		return courseInfo;
	}

	public String toString() {
		return getCourseInfo();
	}

	public int compareTo(Object c)
	{
		Course otherCourse = (Course)c;
		return (courseID.compareTo(otherCourse.courseID));
	}
	
}